home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1995 June / MacFormat 25.iso / Shareware City / Developers / OutOfPhase1.1 Source / OutOfPhase Folder / FastFixedPoint.h < prev    next >
Text File  |  1994-12-30  |  3KB  |  61 lines

  1. /* FastFixedPoint.h */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #ifndef Included_FastFixedPoint_h
  26. #define Included_FastFixedPoint_h
  27.  
  28. /* FastFixedPoint module depends on */
  29. /* MiscInfo.h */
  30. /* Audit */
  31. /* Debug */
  32. /* Definitions */
  33.  
  34. #define FASTFIXEDPRECISION (15)
  35.  
  36. typedef signed long FastFixedType;
  37.  
  38. #define FASTFIXEDFRACTMASK ((((FastFixedType)1L) << FASTFIXEDPRECISION) - 1)
  39.  
  40. #define FastFixedTimes16BitTo24Bit(fastfixed,sixteenbit) (((fastfixed)\
  41.                     * (sixteenbit)) >> (-(24 - (FASTFIXEDPRECISION + 16) + 1)))
  42.  
  43. #define FastFixedTimes8BitTo24Bit(fastfixed,eightbit) (((fastfixed) * (eightbit))\
  44.                     << (24 - (FASTFIXEDPRECISION + 8) + 1))
  45.  
  46. #define FastFixedTimesFastFixedToFastFixed(left,right) (((left)\
  47.                     * (right)) >> FASTFIXEDPRECISION)
  48.  
  49. #define Double2FastFixed(x) ((signed long)((x) * (1L << FASTFIXEDPRECISION)\
  50.                     + ((x >= 0) ? 0.5 : -0.5)))
  51.  
  52. #define FastFixed2Double(x) (((double)(x)) / (1L << FASTFIXEDPRECISION))
  53.  
  54. #define FastFixed2Float(x) (((float)(x)) / (1L << FASTFIXEDPRECISION))
  55.  
  56. #define Int2FastFixed(x) ((signed long)(x) << FASTFIXEDPRECISION)
  57.  
  58. #define FastFixed2Int(x) ((signed long)(x) >> FASTFIXEDPRECISION)
  59.  
  60. #endif
  61.